Here is the most basic and easy way to represent data in the grid view form.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; using System.Data.SqlTypes; namespace FormsApplication1 { publicpartialclassForm4 : Form { public Form4() { InitializeComponent(); } publicvoid fill() { SqlConnection con3 = newSqlConnection(); con3.ConnectionString = (@"Data Source=msclient-012\sqlexpress;Initial Catalog=testing_st;User ID=sa;Password=mindstick"); DataSet ds = newDataSet(); con3.Open(); SqlCommand cmd = newSqlCommand("select A.Enrollment_number,A.Student_name,A.Father_Name,A.Mother_Name,A.Sex,A.Permanent_Add,A.Permanent_State,B.Subject_Maths,B.Subject_Physics,B.Subject_Chemistry,B.Subject_English,B.Subject_Hindi,B.Subject_Social,B.class FROM Std_Details A,Std_Opt_Sub B where A.Enrollment_number = B.Enrollment_number", con3); SqlDataAdapter da = newSqlDataAdapter(); da.SelectCommand = cmd; da.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; } } }
Liked By
Write Answer
How to create grid view in C#, data stored in SQL server?
Join MindStick Community
You have need login or register for voting of answers or question.
Abhishek Srivasatava
22-Oct-2016Here is the most basic and easy way to represent data in the grid view form.